//
// Created by 抑~风 on 2022/12/17.
//

#include<iostream>
#include "../CWJBplusSE.h"
#include "LibrarySys.h"
using namespace std;
using namespace CWJ::BPlusSE;
using namespace CWJ::LibSys;
int main(){

    BPlusTree <CharIndex<20>,Book> tree("Library_book.db",true);
    Book b{1,"cw","www34","pubilc1",100,23};
//    tree.insert("q11q",b);
    tree.insert("q2q",Book{1,"cw","www34","pubilc1",100,23});
    tree.insert("q4q",Book{2,"cj","www12","pubilc2",100,23});
    tree.insert("q5q",Book{3,"cw23j","www45","pubilc1",100,23});
    tree.insert("q2q",Book{5,"cwj1","www6","pubilc3",100,23});
    tree.insert("q7q",Book{8,"cwj46","www8","pubilc4",100,23});
    tree.insert("q8q",Book{9,"cwj86","www4","pubilc1",100,23});

    LibrarySys tool;

    tool.addAcc(Account{"cwj2001","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2002","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2003","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2004","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2005","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2006","123456","yf",12,true,Account::Type::ADMIN});
    tool.addAcc(Account{"cwj2007","123456","yf",12,true,Account::Type::ADMIN});

    for(size_t i=0;i<20;i++){
        CWJ::LibSys::Book book{i,string("bookName"+string(to_string(i))).c_str(),("cc"+to_string(rand()%10)).c_str(),("pp"+to_string(rand()%10)).c_str(),10,0,0,"dddd"};
        tool.addBook(book);
    }


    for(auto itr : tree){
       cout<<"Key: "<<itr.key<<" Value: "<<itr.val<<endl;
   }

    cout<<"--------------------"<<endl;

    LibrarySys tool1;
    for(auto itr : tool1.accounts){
        cout<<"Key: "<<itr.key<<" Value: "<<itr.val<<endl;
    }
    cout<<"--------------------"<<endl;

    for(auto itr = tool.books.begin();itr != tool.books.end();++itr){
        cout<<"Key: "<<itr->key<<" Value: "<<itr->val<<endl;
    }

    cout<<"--------------------"<<endl;

    for(auto itr : tool1.brRecords){
        cout<<"Key: "<<itr.key<<" Value: "<<itr.val<<endl;
    }



    Account acc;
    tool1.accounts.searchKey("cwj2001",acc);

    cout<<acc<<endl;

    cout<<sizeof(Account)<<endl;






}